//
//  ChonZhiViewController.m
//  YDD
//
//  Created by 欧洪飞 on 2017/8/22.
//  Copyright © 2017年 jy. All rights reserved.
//

#import "ChonZhiViewController.h"

#import "BankCardViewController.h"
@interface ChonZhiViewController ()<UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UIView *viewCard;
@property (weak, nonatomic) IBOutlet UIImageView *imageBank;
@property (weak, nonatomic) IBOutlet UILabel *labBank;
@property (weak, nonatomic) IBOutlet UILabel *labCard;

@property (weak, nonatomic) IBOutlet UITextField *textPrice;
@property (weak, nonatomic) IBOutlet UILabel *labDZPrice;

@end

@implementation ChonZhiViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self showNav:@"充值"];
    
    _textPrice.delegate = self;
    _viewCard.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(click)];
    [_viewCard addGestureRecognizer:tap];
    
}

- (void)click{
    BankCardViewController *bank = [[BankCardViewController alloc] init];
    [self.navigationController pushViewController:bank animated:YES];
}

-(void)textFieldDidEndEditing:(UITextField *)textField{
    _labDZPrice.text = [NSString stringWithFormat:@"￥%@",textField.text];
}

//用户充值余额
- (IBAction)clickCZ:(id)sender {
    if (_textPrice.text.length == 0) {
        [self showAlert:@"请输入充值金额"];
        return;
    }
    
    NSString *str = [NSString stringWithFormat:@"%@890d69e502d1d37a9e84335ccefece57",[user objectForKey:@"token2"]];
    NSString *token = [LCMD5Tool md5:str];
    NSMutableDictionary *parmas = [NSMutableDictionary dictionary];
    [parmas setObject:token forKey:@"verifyToken"];
    [parmas setObject:[user objectForKey:@"userid"] forKey:@"userid"];
    [parmas setObject:_textPrice.text forKey:@"rechargeMoney"];
    [parmas setObject:@"alipay" forKey:@"rechargeMode"];
    
    NSString *url = [NSString stringWithFormat:@"%@/App/Usercenter/userRecharge",urlHead];
    [[AFHTTPSessionManager manager] POST:url parameters:parmas success:^(NSURLSessionDataTask *task, id responseObject) {
        NSLog(@"充值余额res:%@",responseObject);
        NSString *state = [NSString stringWithFormat:@"%li",[[responseObject objectForKey:@"status"] integerValue]];
        NSString *msg = [responseObject objectForKey:@"msg"];
        if ([state integerValue] == 200) {
            [SVProgressHUD showSuccessWithStatus:msg];
        }else{
            [SVProgressHUD showErrorWithStatus:msg];
        }
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        NSLog(@"error:%@",error);
    }];
    
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [[UIApplication sharedApplication].keyWindow endEditing:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
